﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TouchControls
{
    public class Tile : Button
    {
        public BitmapSource Icon
        {
            get { return (BitmapSource)GetValue(IconProperty); }
            set { SetValue(IconProperty, value); }
        }

        public double IconSize
        {
            get { return (double)GetValue(IconSizeProperty); }
            set { SetValue(IconSizeProperty, value); }
        }



        public HorizontalAlignment TextAlignment
        {
            get { return (HorizontalAlignment)GetValue(TextAlignmentProperty); }
            set { SetValue(TextAlignmentProperty, value); }
        }

        // Using a DependencyProperty as the backing store for TextAlignment.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty TextAlignmentProperty =
            DependencyProperty.Register("TextAlignment", typeof(HorizontalAlignment), typeof(Tile), new PropertyMetadata(HorizontalAlignment.Left));
        

        // Using a DependencyProperty as the backing store for IconSize.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty IconSizeProperty =
            DependencyProperty.Register("IconSize", typeof(double), typeof(Tile), new PropertyMetadata(48.0));        

        // Using a DependencyProperty as the backing store for Icon.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty IconProperty =
            DependencyProperty.Register("Icon", typeof(BitmapSource), typeof(Tile), null);
        
        static Tile()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(Tile), new FrameworkPropertyMetadata(typeof(Tile)));            
        }

        public Tile()
        {
            IsManipulationEnabled = false;             
        }

        //protected override void OnMouseDown(MouseButtonEventArgs e)
        //{
        //    base.OnMouseDown(e);
        //    IsPressed = true;
        //}

        //protected override void OnMouseLeave(MouseEventArgs e)
        //{
        //    base.OnMouseLeave(e);
        //    IsPressed = false;
        //}

        //protected override void OnMouseUp(MouseButtonEventArgs e)
        //{
        //    base.OnMouseUp(e);
        //    IsPressed = false;
        //}

        //protected override void OnTouchEnter(TouchEventArgs e)
        //{
        //    base.OnTouchEnter(e);
        //    IsPressed = true;
        //}

        //protected override void OnTouchDown(TouchEventArgs e)
        //{
        //    base.OnTouchDown(e);
        //    IsPressed = true;
        //}

        //protected override void OnTouchLeave(TouchEventArgs e)
        //{
        //    base.OnTouchLeave(e);
        //    IsPressed = false;
        //}

        //protected override void OnPreviewTouchDown(TouchEventArgs e)
        //{
        //    base.OnPreviewTouchDown(e);
        //    IsPressed = true;
        //}

        protected override void OnManipulationStarting(ManipulationStartingEventArgs e)
        {
            base.OnManipulationStarting(e);
            e.Handled = false;
        }

        protected override void OnManipulationStarted(ManipulationStartedEventArgs e)
        {
            base.OnManipulationStarted(e);
            e.Handled = false;
        }

        protected override void OnManipulationDelta(ManipulationDeltaEventArgs e)
        {
            base.OnManipulationDelta(e);
            e.Handled = false;
        }

        protected override void OnManipulationCompleted(ManipulationCompletedEventArgs e)
        {
            base.OnManipulationCompleted(e);
            e.Handled = false;
        }
        

        //protected override void OnManipulationCompleted(ManipulationCompletedEventArgs e)
        //{
        //    base.OnManipulationCompleted(e);
        //    if (Math.Abs(e.TotalManipulation.Translation.X) < 5 && Math.Abs(e.TotalManipulation.Translation.Y) < 5)
        //    {
        //        e.Handled = true;
        //    }
        //    IsPressed = false;
        //}
    }
}
